using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using UwinEducation.API.Attributes;
using UwinEducation.Application.Common.Interfaces;
using UwinEducation.Application.Dtos;
using UwinEducation.Shared.Models;

namespace UwinEducation.API.Controllers
{
    /// <summary>
    /// 教师档期管理控制器
    /// </summary>
    [Authorize]
    //[RequirePermission("teacher.course")] // 指定所需的权限
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class TeacherAvailabilityController : ControllerBase
    {
        private readonly ITeacherAvailabilityService _teacherAvailabilityService;

        public TeacherAvailabilityController(ITeacherAvailabilityService teacherAvailabilityService)
        {
            _teacherAvailabilityService = teacherAvailabilityService;
        }

        ///// <summary>
        ///// 创建教师档期
        ///// </summary>
        //[HttpPost]
        //[RequirePermission("teacher.course")] // 指定所需的权限
        //public async Task<ApiResponse<TeacherAvailabilityDto>> Create([FromBody] CreateTeacherAvailabilityDto input)
        //{
        //    var result = await _teacherAvailabilityService.CreateAsync(input);
        //    return ApiResponse<TeacherAvailabilityDto>.Ok(result);
        //}

        /// <summary>
        /// 获取教师的档期列表
        /// </summary>
        [HttpPost]
        public async Task<ApiResponse<BatchCreateTeacherAvailabilityDto>> GetByTeacherId([FromBody] IdRequest request)
        {
            var result = await _teacherAvailabilityService.GetByTeacherIdAsync(request.Id);
            return ApiResponse<BatchCreateTeacherAvailabilityDto>.Ok(result);
        }

        /// <summary>
        /// 获取教师档期分页列表
        /// </summary>
        [HttpPost]
        public async Task<ApiResponse<PagedResult<TeacherAvailabilityDto>>> GetPagedList([FromBody] TeacherAvailabilityPageRequest request)
        {
            var result = await _teacherAvailabilityService.GetPagedListAsync(request);
            return ApiResponse<PagedResult<TeacherAvailabilityDto>>.Ok(result);
        }

        /// <summary>
        /// 获取教师档期分页列表（按是否有排课排序）
        /// </summary>
        [HttpPost]
        public async Task<ApiResponse<PagedResult<TeacherAvailabilityDto>>> GetPagedListWithScheduleStatus([FromBody] TeacherAvailabilityPageRequest request)
        {
            var result = await _teacherAvailabilityService.GetPagedListWithScheduleStatusAsync(request);
            return ApiResponse<PagedResult<TeacherAvailabilityDto>>.Ok(result);
        }

        ///// <summary>
        ///// 获取教师档期详情
        ///// </summary>
        //[HttpPost]
        //public async Task<ApiResponse<TeacherAvailabilityDto>> GetById([FromBody] IdRequest request)
        //{
        //    var result = await _teacherAvailabilityService.GetByIdAsync(request.Id);
        //    return ApiResponse<TeacherAvailabilityDto>.Ok(result);
        //}

        /// <summary>
        /// 更新教师档期
        /// </summary>
        //[HttpPost]
        //public async Task<ApiResponse<TeacherAvailabilityDto>> Update([FromBody] UpdateTeacherAvailabilityDto input)
        //{
        //    var result = await _teacherAvailabilityService.UpdateAsync(input);
        //    return ApiResponse<TeacherAvailabilityDto>.Ok(result);
        //}

        /// <summary>
        /// 删除教师档期
        /// </summary>
        //[HttpPost]
        //public async Task<ApiResponse<object>> Delete([FromBody] IdRequest request)
        //{
        //    await _teacherAvailabilityService.DeleteAsync(request.Id);
        //    return ApiResponse<object>.Ok(new object());
        //}



        /// <summary>
        /// 获取指定日期范围内的教师档期
        /// </summary>
        //[HttpPost]
        //public async Task<ApiResponse<List<TeacherAvailabilityDto>>> GetByDateRange([FromBody] GetTeacherAvailabilityByDateRangeRequest request)
        //{
        //    var result = await _teacherAvailabilityService.GetByDateRangeAsync(request.TeacherId, request.StartDate, request.EndDate);
        //    return ApiResponse<List<TeacherAvailabilityDto>>.Ok(result);
        //}

        /// <summary>
        /// 批量创建教师档期
        /// </summary>
        [HttpPost]
        [RequirePermission("teacher.course")] // 指定所需的权限
        public async Task<ApiResponse<List<TeacherAvailabilityDto>>> BatchCreate([FromBody] BatchCreateTeacherAvailabilityDto inputs)
        {
            var result = await _teacherAvailabilityService.BatchCreateAsync(inputs);
            return ApiResponse<List<TeacherAvailabilityDto>>.Ok(result);
        }
    }
} 